--group by某个字段记录横向展开
SELECT top 5 recv_goods_id,material_id,
[po_bill_no] = stuff((
SELECT ',' + [po_bill_no] + '(' + cast(convert(decimal(18,0),qty) as varchar) + ')'
FROM tb_recv_goods_dtl t with(nolock)
WHERE t.material_id = temp.material_id and t.recv_goods_id = temp.recv_goods_id
FOR xml path('')) , 1 , 1 , '')
FROM tb_recv_goods_dtl temp with(nolock)
GROUP BY recv_goods_id,material_id